package arg

import (
	"reflect"
)

func getFirstLevel() firstLevel {
	return firstLevel{}
}
func getDSN() dSnsLevel {
	return dSnsLevel{}
}
func getDbPool() dbPoolLevel {
	return dbPoolLevel{
		MaxOpenConn:     100,
		MaxIdleConn:     50,
		ConnMaxIdleTime: 500,
		ConnMaxLifeTime: 1000,
	}
}
func getRepair() repairLevel {
	return repairLevel{
		Fix:      "file",
		TrxNum:   1000,
		Binlog:   true,
		FileName: "db2s-DataFix.sql",
		Way:      "split",
	}
}
func getSchema() schemaLevel {
	return schemaLevel{
		Object:       "full",
		TableJoin:    "join",
		IgnoreObject: map[string][]string{},
		GlobalObject: "",
		LowerCase:    false,
	}
}
func getResult() resultLevel {
	return resultLevel{
		Tty:           "bar",
		GeneralResult: true,
		Xls: xlsLevel{
			FileName:     "",
			SafetySwitch: true,
		},
	}
}
func getLogDefVal() logDefVal {
	return logDefVal{
		FilePath: "logs",
		File:     "db2s.log",
		Monitor:  "monitor.log",
		Schedule: "schedule.log",
		SendMsg:  "sendMsg.log",
		Error:    "error.log",
		Level:    "info",
	}
}

func getDSnsCheck(DSnsV DSNsS) dSnsModeCheck {
	//sync,task,count,rows,struct,index,partition,load
	var (
		dnsSetMap = map[string]dnsCheck{
			"source": {Jdbc: DSnsV.SrcJdbc,
				Drive:  DSnsV.SrcDrive,
				DbName: DSnsV.SrcDBName,
			},
			"dest": {Jdbc: DSnsV.DestJdbc,
				Drive:  DSnsV.DestDrive,
				DbName: DSnsV.DestDBName,
			},
		}
	)
	return dSnsModeCheck{
		FunctionalMode: []string{"sync", "task", "rows", "object", "struct", "load"},
		FuncPassParameter: map[string]any{
			"sync":   dnsSetMap,
			"task":   dnsSetMap,
			"rows":   dnsSetMap,
			"struct": dnsSetMap,
			"object": dnsSetMap,
			"load":   dnsSetMap,
			//"load":   map[string]dnsCheck{"source": dnsSetMap["source"]},
		},
	}
}
func getSchemaCheck() schemaModeCheck {
	//sync,task,count,rows,struct,index,partition,load
	return schemaModeCheck{
		FunctionalMode:    []string{"sync", "rows", "struct", "object", "load"},
		FuncPassParameter: map[string]any{},
	}
}
func GetDbPoolCheck() DbPoolModeCheck {
	//sync,task,count,rows,struct,index,partition,load
	return DbPoolModeCheck{
		FunctionalMode:    []string{"sync", "rows", "struct", "object", "load"},
		FuncPassParameter: map[string]any{},
	}
}
func getRepairCheck() repairModeCheck {
	//sync,task,count,rows,struct,index,partition,load
	return repairModeCheck{
		FunctionalMode:    []string{"sync", "rows", "struct", "object", "load"},
		FuncPassParameter: map[string]any{},
	}
}
func getRulesCheck() rulesModeCheck {
	return rulesModeCheck{
		FunctionalMode:    []string{"rows", "struct", "object", "hotSql", "sync", "task", "load"},
		FuncPassParameter: map[string]any{},
		FuncReflect: map[string]reflect.Value{
			"rows":   reflect.ValueOf(rowsParameterCheck),
			"struct": reflect.ValueOf(structParameterCheck),
			"object": reflect.ValueOf(objectParameterCheck),
			"hotSql": reflect.ValueOf(hotSqlParameterCheck),
			"sync":   reflect.ValueOf(syncParameterCheck),
			"task":   reflect.ValueOf(taskParameterCheck),
			"load":   reflect.ValueOf(loadParameterCheck),
		},
	}
}
func getMode() rulesMode {
	return rulesMode{
		Rows:   reflect.ValueOf(rowsRuleParameter),
		Struct: reflect.ValueOf(structRuleArgParameter),
		Object: reflect.ValueOf(objectRuleParameter),
		//Hotsql: reflect.ValueOf(hotSqlRuleParameter),
		Sync: reflect.ValueOf(syncRuleArgParameter),
		Task: reflect.ValueOf(tasksParameter),
		Load: reflect.ValueOf(loadRuleParameter),
	}
}

func getRules() rulesLevel {
	return rulesLevel{
		Mtc:   5,
		Mcc:   10,
		Mrc:   10000,
		Queue: 10000,
	}
}

func getLimit() limitLevel {
	return limitLevel{
		Switch: true,
	}
}

func getRowsRules() rowsLevel {
	return rowsLevel{
		Options:    "crc32",
		Delay:      0,
		Rule:       map[string]string{},
		EndTime:    0,
		IgColumn:   false,
		SqlMode:    false,
		BreakPoint: false,
		Scn:        "0",
	}
}

func getStructRulesDefVal() structLevel {
	return structLevel{
		AlterObject:       []string{"column", "index", "partition"},
		AlterSubObject:    map[string][]string{"column": {"name", "type", "null", "default", "comment"}},
		MapList:           map[string]map[string]string{},
		FixRule:           map[string]map[string]string{"column": {"type": "src", "null": "src", "default": "src", "charset": "src", "collation": "src", "comment": "src"}},
		AlterMethod:       "many",
		BreakPoint:        false,
		SqlLogBin:         false,
		SqlMode:           false,
		WriteParameterOpt: false,
	}
}

func getIndexRules() indexLevel {
	return indexLevel{
		BreakPoint: false,
	}
}

func getSyncRulesDefVal() syncLevel {
	return syncLevel{
		Truncate:          false,
		IgColumn:          false,
		FixRows:           10000,
		SqlMode:           false,
		BreakPoint:        false,
		SqlLogBin:         false,
		Scn:               "0",
		Analyze:           true,
		Recover:           true,
		WriteParameterOpt: false,
		TimeOut:           []int{3600, 60, 60},
		RowsLimit:         0,
	}
}

func getLoadRules() loadLevel {
	return loadLevel{
		Mode:         "output",
		FilePath:     "./dataFix",
		Safe:         true,
		Gzip:         true,
		ColumnSplist: "/*go actions columnData*/",
		RowsSplist:   "/*go actions rowData*/",
		FixRows:      10000,
		IgColumn:     false,
		SqlMode:      false,
		Truncate:     false,
	}
}

func getInspectionFunction() inspectionMode {
	return inspectionMode{
		SlowLog: reflect.ValueOf(rc.slowLevelParameter),
	}
}
func getInspection() inspectionLevel {
	return inspectionLevel{}
}

// 可选值
type (
	//log level
	logLevelOptionalValue struct {
		Debug string `json:"debug"`
		Info  string `json:"info"`
		Warn  string `json:"warn"`
		Error string `json:"error"`
	}
	// repair rule Optional
	repairFixSqlRulesOptionValue struct {
		File  string `json:"file"`
		Table string `json:"table"`
		No    string `json:"no"`
	}
	objectRulesOptionValue struct {
		View    string `json:"view"`
		Job     string `json:"job"`
		Func    string `json:"func"`
		Trigger string `json:"trigger"`
		Packge  string `json:"packge"`
		Foreign string `json:"foreign"`
		Seq     string `json:"seq"`
	}
	// repair rule Optional
	repairFixSqlFileOptionValue struct {
		Split string `json:"split"`
		Many  string `json:"many"`
	}
	//rules struct check Optional
	structCheckObjectOptionalValue struct {
		Name      string `json:"name"`
		Type      string `json:"type"`
		Null      string `json:"null"`
		Default   string `json:"default"`
		Charset   string `json:"charset"`
		Collation string `json:"collation"`
		Comment   string `json:"comment"`
		All       string `json:"all"`
	}
	//rules struct fix rule Optional
	structFixRuleOptionValue struct {
		Single string `json:"single"`
		Many   string `json:"many"`
	}
)
